<!DOCTYPE html>
<html>
<head>
<title>网上订单-速订客</title>
<meta ht_topp-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta ht_topp-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta name="keyword" content="">
<meta name="description" content="">
<link rel="stylesheet" rev="stylesheet" href="<?=STATIC_URL;?>css/base.css" type="text/css">
<link rel="stylesheet" rev="stylesheet" href="<?=STATIC_URL;?>css/order.css" type="text/css">
<link rel="icon" type="image/x-icon" href="<?=STATIC_URL;?>favicon.ico">
<link rel="shortcut icon" type="image/x-icon" href="<?=STATIC_URL;?>favicon.ico">
</head>
<body>
<?php include dirname(__FILE__).'/../com-header-sample.tpl.php'; ?>
<!------------------------------------>

<form action="/order/done" method="post" name="submitForm" id="submitForm">
    <input type="hidden" name="shop_id" value="<?=i($shop['shop_id']);?>" />
    <input type="hidden" name="shop_name" value="<?=h($shop['name']);?>" />
    <input type="hidden" name="verify" value="<?=h($verify);?>" />
<div id="container">
  <div class="order_table">
    <h2 class="navbar">菜单明细 - <a href="/shop/<?=i($shop['shop_id']);?>" style="color:#fff;font-weight:normal"><?=h($shop['name']);?></a></h2>
    <div class="box_top">
      <table class="t_top">
        <thead>
          <tr>
            <th>序号</th>
            <th>美食名称</th>
            <th>原价</th>
            <th>折扣价</th>
            <th>数量</th>
            <th>小计</th>
            <th>口味</th>
          </tr>
        </thead>
        <tbody id="cartTable">
<?php
    $i = $price = $money = $total = 0;
    foreach($data as $item){
         $money = doubleval($item['number']*$item['money']); //标价
         $price = doubleval($item['number']*$item['price']); //售价（折扣后价格）
?>
          <tr id="dish_<?=$item['dish_id'];?>">
            <td><?=(++$i);?></td>
            <td><?=h($item['name']);?></td>
            <td><s><span class="money"><?=h($item['money']);?></span>元</s></td>
            <td><span class="price"><?=h($item['price']);?></span>元</td>
            <td align="center"><input type="text" name="itemNum[<?=$item['dish_id'];?>]" size="4" value="<?=h($item['number']);?>" autocomplete="off" onClick="changePrice(<?=$item['dish_id'];?>)" onchange="changePrice(<?=$item['dish_id'];?>)" /></td>
            <td><span class="count"><?=h($price);?></span></td>
            <td><a href="#" onclick="delCart(<?=$item['dish_id'];?>)">删除</a></td>
          </tr>
<?php
        $total += $price;
    }
?>
        </tbody>
        <tfoot>
          <tr>
            <td colspan="7" style="border:none;height:40px;text-align:right">合计：<span id="totalfee" class="price"><?=$total;?></span> 元，节省：<span id="savefee" class="price">0</span> 元<!--，积分51分--></td>
          </tr>
        </tfoot>
      </table>
    </div>

    <h2 class="navbar">送餐信息</h2>
    <div style="background-color:#FFFFCC;padding: 10px;width:940px;" class="clear">
      <div class="last_payment_info"> <span><b>菜单金额：</b><span id="last_totalfee" class="price">0</span>元;&nbsp;&nbsp;</span>
        <span id="forservice"><b>服务费：</b><span id="last_servicefee" class="price">0</span>元;&nbsp;&nbsp;</span>
        <span class=""> <b>共节省：</b><span id="last_savefee" class="price">0</span>元;&nbsp;&nbsp;
        <!--b>您需为本单支付：￥</b><b id="total" class="price large">0</b--> </span> </div>
    </div>
    <div class="box_bot">
      <input type="hidden" name="fromtype" value="waimai" />
      <input type="hidden" name="dosubmit" value="yes" />
      <table class="t_bot">
        <tbody>
          <tr>
            <th width="100">联 系 人</th><td align="left"><input type="text" name="realname" id="realname" />
            <span class="tip" id="realnameTip"></span></td>
          </tr>
          <tr>
            <th>手 &nbsp;&nbsp; &nbsp;&nbsp; 机</th><td align="left"><input type="text" name="mobile" id="mobile" />
            <span class="tip" id="mobileTip"></span></td>
          </tr>
          <tr>
            <th>备用电话</th><td align="left"><input type="text" name="telphone" id="telphone" />
            <span class="tip" id="telphoneTip"></span></td>
          </tr>
          <tr>
            <th>送餐地址</th><td align="left"><input type="text" name="address" size="50" id="address" />
            <span class="tip" id="addressTip"></span></td>
          </tr>
          <tr>
            <th valign="top">备 &nbsp;&nbsp; &nbsp;&nbsp; 注</th><td align="left"><textarea name="memo" class="inp" id="memo" cols="48"></textarea>
            <span class="tip" id="memoTip"></span></td>
          </tr>
        </tbody>
        <tfoot>
          <tr>
            <td colspan="3"><button class="btns" type="submit">提交订单</button></td>
          </tr>
        </tfoot>
      </table>
    </div>
    <p>&nbsp;</p>
  </div>
</div>
</form>

<!------------------------------------>
<? include dirname(__FILE__).'/../com-footer.tpl.php'; ?>
<script type="text/javascript" src="<?=STATIC_URL;?>js/jquery-1.7.1.min.js"></script>
<script src="<?=STATIC_URL;?>js/validator/formValidator-4.1.1.js" type="text/javascript" charset="UTF-8"></script>
<script src="<?=STATIC_URL;?>js/validator/formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
function delCart(id){
    if(confirm('确实要删除该菜品么？')){
        $("#dish_" + id).remove();
    }
    totalPrice();
}

function changePrice(id){
    var oTr = $("#dish_" + id);
    var count = parseInt(oTr.find("input").val(), 10) * parseFloat(oTr.find(".price").html(), 10)
    oTr.find(".count").html(count);

    totalPrice();
}

function totalPrice(){
    var oItem = $("#cartTable").find("tr");
    var cnt   = oItem.size();
    var money = 0; //标价
    var price = 0; //售价
    oItem.each(function(){
        money += parseInt($(this).find("input").val(), 10) * parseFloat($(this).find(".money").html(), 10);
        price += parseInt($(this).find("input").val(), 10) * parseFloat($(this).find(".price").html(), 10);
    });

    $("#totalfee,#last_totalfee").html(price);
    $("#savefee,#last_savefee").html(money - price);
}
</script>
<script type="text/javascript">
var onShowHtml = "";
var onFocusHtml = "<span class='$class$'>$data$</span>";
var onErrorHtml = "<span class='$class$'>$data$</span>";
var onCorrectHtml = "<span class='$class$'></span>";
var onShowClass = "inp";
var onFocusClass = "inp inp_focus";
var onErrorClass = "inp inp_error";
var onCorrectClass = "inp inp_correct";

$(document).ready(function(){
    totalPrice();

    $.formValidator.initConfig({formID:"submitForm",mode:'FixTip',onError:function(msg){/*alert(msg)*/},onSuccess:function(){return window.confirm("确认您的联系方式填写准确，以便我们及时送餐。\n现在立即提交么？");},inIframe:true,ajaxPrompt:""});
    $("#realname").formValidator({onShow:"请输入联系人姓名",onFocus:"请输入联系人姓名",onCorrect:"联系人输入正确"}).inputValidator({min:2,onError:"请输入联系人姓名"});
    $("#mobile").formValidator({onShow:"请输入手机号码",onFocus:"请输入正确的手机号码，以备联络",onCorrect:"手机号码输入正确"}).inputValidator({min:11,max:11,onError:"手机号码格式错误"}).regexValidator({regExp:"mobile",dataType:"enum",onError:"你输入的电话号码格式不正确"});
    $("#telphone").formValidator({empty:true,onShow:"请输入备用电话",onFocus:"请输入正确的备用电话号码",onCorrect:"备用电话输入正确"}).inputValidator({min:6,max:13,onError:"电话号码必须是数字格式"}).regexValidator({regExp:"num",dataType:"enum",onError:"你输入的电话号码格式不正确"});
    $("#address").formValidator({onShow:"请输入详细送餐地址",onFocus:"送餐地址不能为空",onCorrect:"送餐地址输入正确"}).inputValidator({min:1,onError:"请输入详细送餐地址"});
    $("#memo").formValidator({empty:true,onShow:"请输入附加信息，可以为空",onFocus:"如：送餐时间，咸淡，是否加辣等要求",onCorrect:"输入正确",onEmpty:""});
    $.formValidator.reloadAutoTip();
});
</script>
</body>
</html>